//
//  ViewController.m
//  IOS-image-custom
//
//  Created by RIOS on 2018/3/28.
//  Copyright © 2018年 RIOS. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (nonatomic) UIButton *image;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self initBtn];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)initBtn {
    self.image = [UIButton new];
    CGRect rect = CGRectMake(22, 22, 100, 100);
    self.image.frame =rect;
    [self.image setBackgroundImage:[UIImage imageNamed:@"image7"] forState:UIControlStateNormal];
    [self.image setBackgroundImage:[UIImage imageNamed:@"image8"] forState:UIControlStateHighlighted];
    [self.image setTitle:@"点我吧" forState:UIControlStateNormal];
    [self.image setTitle:@"摸我干啥!" forState:UIControlStateHighlighted];
    [self.image setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];
    [self.image setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [self.view addSubview:self.image];
    
    UIButton *moveLeft = [UIButton new];
    [moveLeft setBackgroundImage:[UIImage imageNamed:@"arrowleft"] forState:UIControlStateNormal];
    moveLeft.tag = -1;
    [moveLeft addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    CGRect recta = CGRectMake(22, 180, 50, 50);
    moveLeft.frame =recta;
    [self.view addSubview:moveLeft];
    
    UIButton *moveRight = [UIButton new];
    moveRight.tag =1;
    [moveRight setBackgroundImage:[UIImage imageNamed:@"arrowright"] forState:UIControlStateNormal];
    [moveRight addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    CGRect rect3 = CGRectMake(122, 180, 50, 50);
    moveRight.frame =rect3;
    [self.view addSubview:moveRight];
    
}

- (void) btnClick:(UIButton *)btn{
    NSLog(@"点击了%ld",btn.tag);
    CGRect frame = self.image.frame;
    frame.origin.x += 100*btn.tag;
    [UIView animateWithDuration:0.5 animations:^{
        
        self.image.frame = frame;
    }];
}
















@end
